import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bala here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bala extends Actor
{
    private Heroe heroe;
    // private Monster mons;
    /**
     * Act - do whatever the Bala wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */

    public Bala(Heroe heroe)
    {
        this.heroe=heroe;
    }

    public void act() 
    {
        detectWall();
        //  this.heroe=heroe;
    }   

    public void detectWall()
    {
        World world=getWorld();
        Wall1 wall=(Wall1)getOneIntersectingObject(Wall1.class);
        Wall2 wall2=(Wall2)getOneIntersectingObject(Wall2.class);
        Wall3 wall3=(Wall3)getOneIntersectingObject(Wall3.class);
        Wall4 wall4=(Wall4)getOneIntersectingObject(Wall4.class);

        if(world instanceof Fortaleza)
        {
            if(wall==null && wall2==null )
            {
                impactEnemy();    
            }
            else 
                getWorld().removeObject(this);
        }

        if(world instanceof Fortaleza2 || world instanceof Fortaleza3)
        {
            if(wall3==null && wall4==null )
            {
                impactEnemy();    
            }
            else 
                getWorld().removeObject(this);
        }
    }

    public void impactEnemy()
    {
        World world=getWorld();
        move(5);
    //    if(world instanceof Fortaleza2)
      //  {
            Monster mons=(Monster)getOneIntersectingObject(Monster.class);   
            if(mons!=null)
            {
                if(mons.isDead()==false)
                {
                    mons.decreaseResistance();
                    heroe.incrementaMonedas();
                }
                else
                    getWorld().removeObject(mons);
         //   }
        }
      /*      if(world instanceof Fortaleza)
            {

                java.util.List lista = getIntersectingObjects( Monster.class );
                if(!lista.isEmpty())
                {
                    World mundo=getWorld();
                    heroe.incrementaMonedas();
                    getWorld().removeObjects(lista);

                }

            }
        }*/
    }
}

